<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" id="batchUpload" action="user/upload" method="post" class="form-horizontal">
    <button class="btn btn-success btn-xs" id="uploadEventBtn" style="height:26px;" type="button">选择文件</button><br>
    <input type="file" name="file" style="width:0px;height:0px;" id="uploadEventFile"><br>
    <input id="uploadEventPath" disabled="disabled" type="text"><br>
</form><br>
<button type="button" class="btn btn-success btn-sm" onclick="user.uploadBtn()">上传</button>
</body>
<script>
    var User = function () {
        this.init = function () {
            //模拟上传excel
            $("#uploadEventBtn").unbind("click").bind("click", function () {
                $("#uploadEventFile").click();
            });
            $("#uploadEventFile").bind("change", function () {
                $("#uploadEventPath").attr("value", $("#uploadEventFile").val());
            });
        };
        //点击上传按钮
        this.uploadBtn = function () {
            var uploadEventFile = $("#uploadEventFile").val();
            if (uploadEventFile == '') {
                alert("请选择excel,再上传");
            } else if (uploadEventFile.lastIndexOf(".xls") < 0) {//可判断以.xls和.xlsx结尾的excel
                alert("只能上传Excel文件");
            } else {
                var url = 'classteacher/addCollegeEntranceScore';
                var formData = new FormData($('form')[0]);
                user.sendAjaxRequest(url, 'POST', formData);
            }
        };
        this.sendAjaxRequest = function (url, type, data) {
            $.ajax({
                url: url,
                type: type,
                data: data,
                success: function (result) {
                    alert(result.code);
                },
                error: function () {
                    alert("excel上传失败");
                },
                cache: false,
                contentType: false,
                processData: false
            });
        };
    }
    var user;
    $(function () {
        user = new User();
        user.init();
    });
</script>
</html>